{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{# load mytags  #}

<link href="/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">               
        <div class="col-lg-12"> 
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据库初始化</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>        
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">未启用 1</a>
                            </li>
                            <li><a href="#">未启用 2</a>
                            </li>
                        </ul>   
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
            
                <div class="ibox-content">
                    <div class="row">
                    <div class="col-sm-4 m-b-xs">
                        {% for num in inc_area_info %}
                            <a  class="btn btn-primary btn-write" href="?project={{project}}&zone={{num}}"> {{num}}</a>
                        {% endfor %}
                    </div>
                    </div>
                    <form id="contents_form" name="contents_form">
                    <table class="table table-striped table-bordered table-hover dataTables-example" >
                        <thead>
                            <tr>
                                <th class="text-center">编号</th>
                                <th class="text-center">项目名称</th>
                                <th class="text-center">地区</th>
                                <th class="text-center">服务器类型</th>
                                <th class="text-center">数据库IP</th>
                                <th class="text-center">数据库用途</th>
                                <th class="text-center">关联的服务器IP</th>
                                <th class="text-center">备注</th>
                                <th class="text-center">是否初始化</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for num in db_info %}
                          <tr class="text-center">
                            <td>
                            {% ifequal num.db_init 1%}
                                {{forloop.counter}}.<input type="checkbox" data-toggle="checkbox" name="nochoice" DISABLED>
                            {% else %}
                                {{forloop.counter}}.<input type="checkbox" data-toggle="checkbox" name="choice_host" value={{ num.p_ip }}>
                            {% endifequal %}
                            </td>
                            <td>{{num.project.mini_name}}</td>
                            <td>{{num.area}}</td>
                            <td>{{num.platform.mini_name}}</td>
                            <td>{{num.db_ip}}</td>
                            <td>{% for use in num.use.all %} {{use}}{% endfor %}</td>
                            <td>{{num.p_ip}}</td>
                            <td>{{num.commit}}</td>
                            <td>
                              {% ifequal num.db_init 1 %}
                                <font color="green">已初始化</font>
                              {% else %}
                                <font color="red">未初始化</font>
                              {% endifequal %}
                            </td>
                          </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    <!--<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">全选/全不选 -->
                    <input type="radio" data-toggle="radio"  name="checkradio" id="SelectAll" data-radiocheck-toggle="radio" onclick="choice(valu='all')" >全选
                            <input type="radio" data-toggle="radio" name="checkradio" id="SelectAll"  data-radiocheck-toggle="radio" onclick="choice(valu='no')">反选
                    <div class="hr-line-dashed"></div>
                    <div class="input-group col-xs-4 has-success">
                        <span class="input-group-addon">数据库初始密码</span>
                        <input type="text" name="db_passwd" class="form-control" placeholder="" id="db_passwd">
                    </div><br>

                    </form>
                    <button type="submit" class="btn btn-success dim" name="switch" form="contents_form" formmethod="post" formaction="/inc/db_init_process/?project={{project}}&area={{zone}}">执行初始化</button>
                    <button type="submit" class="btn btn-warning dim" name="switch" form="contents_form" formmethod="post" formaction="/inc/db_init/?action=set_db_init">设置已初始化</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>
<script type="text/javascript">
    function choice(valu){
                var ids=$("input[name='choice_host']");
                if (valu == "all"){
　　                    for(var i=0;i<ids.length;i++){
　　　　                        ids[i].checked="checked";  
　　                    }                       
                }else if (valu == "no") {
　　                    for(var i=0;i<ids.length;i++){
　　　　                ids[i].checked="";  
　　                    }
                }
        };

    $(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "tableTools": {
                    "aButtons":false,
                    //"sSwfPath": "/static/js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });
        });
</script>

{% endblock %}
